<?php

/**
 * @name: rayauth.class.php
 * @version: 1.0
 * @package: PHP MVC Framework
 * @uses: Handles getting and sending of user data for security
 * @copyright: MIT
 * @author Andrew Lowther
 */
 
 class RayAuth {
 	
 	public function __construct($registry, $username, $password) {
 		
 		$sanuser = mysql_real_escape_string($username);
        $sanpass = mysql_real_escape_string($password);

        $md5pass = md5($sanpass);

        $login = $registry->db->setQuery(sprintf("SELECT * FROM `users` WHERE `username` = '%s' AND `password` = '%s'", $sanuser, $md5pass));

        $count = mysql_num_rows($login);

        if ($count < 1 || $count > 1) {

            return false;

        } else {

            $registry->session->loggedin = true;
            return true;

        }
 		
 	}
 	
 }
 
 ?>